package com.zystudio.func.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.zystudio.func.R;
import com.zystudio.func.other.PolicyEntity;
import java.util.ArrayList;
import java.util.List;

public class PolicyActivity extends Activity {

    private ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zy_func_policy);
        listView = findViewById(R.id.policy_list);
        initListView();
    }

    private void initListView(){
        AdapterPolicy adapter = new AdapterPolicy(this,generateData());
        listView.setAdapter(adapter);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PolicyEntity entity = (PolicyEntity) parent.getItemAtPosition(position);
                startWeb(entity.getUrl());
            }
        });
    }
    private void startWeb(String url){

        Intent intent = new Intent(this, WebActivity.class);
        intent.putExtra("url",url);
        startActivity(intent);

    }

    private List<PolicyEntity> generateData(){

        List<PolicyEntity> list = new ArrayList<>();
        list.add(new PolicyEntity("魔力引擎","http://wugua.com.cn/mlPrivacy.html"));
        list.add(new PolicyEntity("广州果宝","http://imagicengine.com/zgPrivacy.html"));
        list.add(new PolicyEntity("河南无瓜","http://www.wugua.com.cn/yinsi.html"));
        list.add(new PolicyEntity("成都纸鸢","http://wugua.com.cn/czPrivacy.html"));
        list.add(new PolicyEntity("青松","http://imagicengine.com/soPrivacy.html"));
        list.add(new PolicyEntity("轻舟","http://imagicengine.com/qzPrivacy.html"));
        list.add(new PolicyEntity("纸阁","http://imagicengine.com/gePrivacy.html"));
        return list;

    }
}
